package com.bfb.helpers;

import java.util.ArrayList;

public class ListUtilities {

	/**
	 * @author Rana This method returns a string representation of an ArrayList
	 *         of strings. Elements are delimited by commas
	 * 
	 * @param input
	 * @return {@link String}
	 */
	public static String listToString(ArrayList<String> input) {

		String result = "";
		for (int i = 0; i < input.size(); i++) {
			if (i == 0)
				result = result + input.get(i);
			else
				result = result + "," + input.get(i);
		}
		return result;
	}

	/**
	 * @author Rana This method takes a string of CSV and returns an arraylist
	 *         of the values
	 * @param input
	 * @return {@link ArrayList}
	 */
	public static ArrayList<String> stringToList(String input) {
		String[] temp = input.split(",");
		ArrayList<String> result = new ArrayList<String>();
		if (!input.equals(""))
			for (int i = 0; i < temp.length; i++) {
				result.add(temp[i]);
			}
		return result;
	}

	/**
	 * @author Rana This method returns true if both arrayLists contain the same
	 *         elements even if in different orders
	 * 
	 * @param arr1
	 * @param arr2
	 * @return boolean
	 */
	public static boolean listsAreEqual(ArrayList<String> arr1,
			ArrayList<String> arr2) {
		for (int i = 0; i < arr1.size(); i++) {
			if (!arr2.contains(arr1.get(i)))
				return false;

		}
		return true;
	}
}
